<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/10/21 0021
 * Time: 17:20
 */

namespace app\controllers;




use app\common\base\BaseController;
use app\models\TbArticle;
use app\models\TbFilecomment;
use app\models\TbPublic;
use app\models\TbUser;
use Yii;
use yii\web\Controller;

class FilecommentController extends BaseController
{
    public function actionComment($id){
        $article=TbArticle::selectid($id);
        $comment=TbFilecomment::selectidtime($id);
        $countries =TbPublic::selecttopfives();
        $topten=TbUser::ToptenCelebrity();
        return $this->render('comments',[
            'article'=>$article,
            'comment'=>$comment,
            'countries'=>$countries,
            'r'=>$topten
        ]);
    }
    /**
     * 添加评论
     * @return string
     */
    public function actionAddcomment(){
        $tbfilecomment = new TbFilecomment();
        $username = Yii::$app->session->get('regname');
        $fid = $this->getParam('fid');
        $question_detail = $this->getParam('question_detail');
        date_default_timezone_set('PRC');//设置中国时区
        $datetime = date('Y-m-d H:i:s',time());//获取当前系统时间
        $tbfilecomment->fileid = $fid;
        $tbfilecomment->username = $username;
        $tbfilecomment->content = $question_detail;
        $tbfilecomment->datetime=$datetime;
        if ($tbfilecomment->save()){
            $article=TbArticle::selectid($fid);
            $comment=TbFilecomment::selectidtime($fid);
            $countries =TbPublic::selecttopfives();
            $topten=TbUser::ToptenCelebrity();
            return $this->render('comments',[
                'article'=>$article,
                'comment'=>$comment,
                'countries'=>$countries,
                'r'=>$topten
                ]);
        }
        return $this->out(false,'评论失败');
    }
}